--------------------------------------------------------------------------------------------------------
      name:  rep
       log:  /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict project/Co
> nflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/01_clean.log
  log type:  text
 opened on:   7 Dec 2025, 15:14:20
r; t=0.00 15:14:20

. 
. 
. //global data   "data/"
. //global graph  "graph/"
. //global table  "tables/"
. 
. 
. ***************************************************************
. * 1. AFROBAROMETER R9 – DATES, TIME VAR, DEMOGRAPHICS, OUTCOMES
. ***************************************************************
. 
. use "${data}/Original_data_R9.dta", clear
r; t=2.11 15:14:22

. 
. *--------------------------------------------------------------
. * 1.1 Interview date and time within country
. *--------------------------------------------------------------
. 
. * Numeric interview date
. gen intervdate = DATEINTR
r; t=0.00 15:14:22

. format intervdate %td
r; t=0.00 15:14:22

. label var intervdate "Interview date (numeric Stata date)"
r; t=0.00 15:14:22

. 
. * Fieldwork window (global)
. summ intervdate if !missing(intervdate)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
  intervdate |     20,463     22826.7    136.7338      22596      23183
r; t=0.00 15:14:22

. scalar field_start = r(min)
r; t=0.00 15:14:22

. scalar field_end   = r(max)
r; t=0.00 15:14:22

. 
. display "Fieldwork start: " %td field_start
Fieldwork start: 12nov2021
r; t=0.00 15:14:22

. display "Fieldwork end:   " %td field_end
Fieldwork end:   22jun2023
r; t=0.00 15:14:22

. 
. * Time since first interview within country
. egen min_intervdate = min(intervdate), by(COUNTRY)
r; t=0.00 15:14:22

. gen time_interviewed = intervdate - min_intervdate + 1 if !missing(intervdate)
r; t=0.00 15:14:22

. drop min_intervdate
r; t=0.00 15:14:22

. label var time_interviewed "Day of fieldwork within country (1 = first day)"
r; t=0.00 15:14:22

. 
. *--------------------------------------------------------------
. * 1.2 DEMOGRAPHIC VARIABLES
. *--------------------------------------------------------------
. 
. * Recode and generate variables for age
. tab Q1, nolabel  // Check numeric codes for "Refused" and "Don't know"

Respondent' |
      s age |      Freq.     Percent        Cum.
------------+-----------------------------------
         18 |        615        3.01        3.01
         19 |        646        3.16        6.17
         20 |        703        3.44        9.60
         21 |        475        2.32       11.93
         22 |        672        3.29       15.21
         23 |        552        2.70       17.91
         24 |        484        2.37       20.28
         25 |        967        4.73       25.01
         26 |        525        2.57       27.58
         27 |        534        2.61       30.19
         28 |        756        3.70       33.88
         29 |        483        2.36       36.25
         30 |        932        4.56       40.80
         31 |        326        1.59       42.40
         32 |        691        3.38       45.78
         33 |        382        1.87       47.65
         34 |        394        1.93       49.57
         35 |        841        4.11       53.68
         36 |        438        2.14       55.83
         37 |        358        1.75       57.58
         38 |        491        2.40       59.98
         39 |        337        1.65       61.63
         40 |        768        3.76       65.38
         41 |        295        1.44       66.82
         42 |        484        2.37       69.19
         43 |        277        1.35       70.55
         44 |        191        0.93       71.48
         45 |        585        2.86       74.34
         46 |        200        0.98       75.32
         47 |        269        1.32       76.63
         48 |        341        1.67       78.30
         49 |        185        0.90       79.21
         50 |        486        2.38       81.58
         51 |        149        0.73       82.31
         52 |        322        1.57       83.89
         53 |        186        0.91       84.80
         54 |        190        0.93       85.73
         55 |        257        1.26       86.98
         56 |        157        0.77       87.75
         57 |        152        0.74       88.49
         58 |        218        1.07       89.56
         59 |        111        0.54       90.10
         60 |        330        1.61       91.72
         61 |        114        0.56       92.27
         62 |        151        0.74       93.01
         63 |        129        0.63       93.64
         64 |         85        0.42       94.06
         65 |        205        1.00       95.06
         66 |         83        0.41       95.47
         67 |         93        0.45       95.92
         68 |         76        0.37       96.29
         69 |         72        0.35       96.65
         70 |        162        0.79       97.44
         71 |         43        0.21       97.65
         72 |         63        0.31       97.96
         73 |         55        0.27       98.22
         74 |         47        0.23       98.45
         75 |         77        0.38       98.83
         76 |         30        0.15       98.98
         77 |         24        0.12       99.10
         78 |         30        0.15       99.24
         79 |         23        0.11       99.35
         80 |         39        0.19       99.55
         81 |          6        0.03       99.57
         82 |         15        0.07       99.65
         83 |         12        0.06       99.71
         84 |          7        0.03       99.74
         85 |         15        0.07       99.81
         86 |          5        0.02       99.84
         87 |          7        0.03       99.87
         88 |          5        0.02       99.90
         89 |          3        0.01       99.91
         90 |          4        0.02       99.93
         91 |          1        0.00       99.94
         92 |          3        0.01       99.95
         94 |          1        0.00       99.96
         95 |          3        0.01       99.97
         97 |          2        0.01       99.98
         99 |          1        0.00       99.99
        100 |          2        0.01      100.00
        103 |          1        0.00      100.00
------------+-----------------------------------
      Total |     20,449      100.00
r; t=0.00 15:14:22

. replace Q1 = . if Q1 == 998 | Q1 == 999  // Replace based on numeric codes
(0 real changes made)
r; t=0.00 15:14:22

. clonevar age = Q1
(14 missing values generated)
r; t=0.00 15:14:22

. 
. * Gender (0 = male, 1 = female)
. recode Q100 (1 = 0) (2 = 1), gen(gender)
(20,463 differences between Q100 and gender)
r; t=0.03 15:14:22

. label define gender_lbl 0 "Male" 1 "Female"
r; t=0.00 15:14:22

. label values gender gender_lbl
r; t=0.00 15:14:22

. label var gender "Gender of respondent"
r; t=0.00 15:14:22

. 
. * Race (grouped) from Q101
. recode Q101 ///
>     (1 = 1) /// Black / African  
>     (2 = 2) /// White / European  
>     (3 = 3) /// Coloured / Mixed race  
>     (4 = 4) /// Arab / Lebanese / North African  
>     (5 = 5) /// South Asian  
>     (6 = 5) /// East Asian -> grouped with South Asian  
>     (9995 = 6) /// Other  
>     (9999 = .), gen(race)
(8 differences between Q101 and race)
r; t=0.01 15:14:22

. 
. label define race_lbl ///
>     1 "Black / African" ///
>     2 "White / European" ///
>     3 "Coloured / Mixed race" ///
>     4 "Arab / Lebanese / North African" ///
>     5 "Asian (South & East Asian)" ///
>     6 "Other"
r; t=0.00 15:14:22

. 
. label values race race_lbl
r; t=0.00 15:14:22

. label var race "Race of respondent (grouped)"
r; t=0.00 15:14:22

. 
. recode race (1 = 1) (2 = 2) (3/6 = 3), gen(race_group)
(840 differences between race and race_group)
r; t=0.00 15:14:22

. label define race_group_lbl ///
>     1 "Black / African" ///
>     2 "White / European" ///
>     3 "Others", replace
r; t=0.00 15:14:22

. label values race_group race_group_lbl
r; t=0.00 15:14:22

. //tab race
. 
. 
. * Religion (grouped) from Q95
. recode Q95 ///
>     (0 = 5) /// None
>     (1 2 3 4 = 2) /// Christian (unspecified + Catholic/Orthodox/Coptic)
>     (5 6 7 8 9 10 11 12 13 14 15 16 17 30 31 32 33 100 420 500 740 780 820 821 822 823 = 3) /// Protes
> tant / other Christian
>     (18 19 20 21 22 23 24 = 1) /// Muslims (all)
>     (25 = 4) /// Traditional/Ethnic religion
>     (26 27 28 29 34 9994 9995 = 5) /// Others, none/agnostic/atheist/not asked
>     (9998 = .) ///
>     (9999 = .) ///
>     (-1 = .), gen(religion)
(18,114 differences between Q95 and religion)
r; t=0.06 15:14:22

. 
. label define religion_lbl ///
>     1 "Muslim (all groups)" ///
>     2 "Christian (all groups)" ///
>     3 "Protestant (all groups)" ///
>     4 "Traditional/Ethnic religion" ///
>     5 "Others"
r; t=0.00 15:14:22

. 
. label values religion religion_lbl
r; t=0.00 15:14:22

. label var religion "Religious affiliation (grouped)"
r; t=0.00 15:14:22

. tab religion

      Religious affiliation |
                  (grouped) |      Freq.     Percent        Cum.
----------------------------+-----------------------------------
        Muslim (all groups) |      7,510       36.78       36.78
     Christian (all groups) |      7,017       34.37       71.14
    Protestant (all groups) |      4,412       21.61       92.75
Traditional/Ethnic religion |        360        1.76       94.51
                     Others |      1,120        5.49      100.00
----------------------------+-----------------------------------
                      Total |     20,419      100.00
r; t=0.00 15:14:22

. 
. * Urban–rural (URBRUR)
. recode URBRUR (1 = 1) (2 3 = 2), gen(urban_rural)
(32 differences between URBRUR and urban_rural)
r; t=0.01 15:14:22

. label define urban_rural_lbl 1 "Urban" 2 "Rural"
r; t=0.00 15:14:22

. label values urban_rural urban_rural_lbl
r; t=0.00 15:14:22

. label var urban_rural "Urban-Rural"
r; t=0.00 15:14:22

. 
. * Ethnic group – just clean missing codes -> .
. recode Q84A (-1 9990 9994 9995 9998 9999 = .), gen(ethnic)
(1,921 differences between Q84A and ethnic)
r; t=0.01 15:14:22

. label var ethnic "Ethnic group"
r; t=0.00 15:14:22

. 
. * Education (recoded + broader groups) from Q94
. recode Q94 ///
>     (0 = 0) ///
>     (1 = 1) ///
>     (2 = 2) ///
>     (3 = 3) ///
>     (4 = 4) ///
>     (5 = 5) ///
>     (6 = 6) ///
>     (7 = 7) ///
>     (8 = 8) ///
>     (9 = 9) ///
>     (98 = .) ///
>     (99 = .), gen(recoded_education)
(37 differences between Q94 and recoded_education)
r; t=0.01 15:14:22

. 
. label define education_lbl ///
>     0 "No formal schooling" ///
>     1 "Informal schooling only" ///
>     2 "Some primary schooling" ///
>     3 "Primary school completed" ///
>     4 "Some secondary / high school" ///
>     5 "Secondary / high school completed" ///
>     6 "Post-secondary, non-university" ///
>     7 "Some university" ///
>     8 "University completed" ///
>     9 "Post-graduate"
r; t=0.00 15:14:22

. 
. label values recoded_education education_lbl
r; t=0.00 15:14:22

. label var recoded_education "Re-coded Education Levels"
r; t=0.00 15:14:22

. 
. * Broader education groups
. recode recoded_education (0 1 2 = 1) (3 4 = 2) (5 6 7 = 3) (8 9 = 4), gen(educ_group)
(19,612 differences between recoded_education and educ_group)
r; t=0.01 15:14:22

. label define educ_group_lbl ///
>     1 "Below primary" ///
>     2 "Primary" ///
>     3 "Secondary" ///
>     4 "University"
r; t=0.00 15:14:22

. label values educ_group educ_group_lbl
r; t=0.00 15:14:22

. label var educ_group "Education level"
r; t=0.00 15:14:22

. tab educ_group

    Education |
        level |      Freq.     Percent        Cum.
--------------+-----------------------------------
Below primary |      7,244       35.46       35.46
      Primary |      6,386       31.26       66.73
    Secondary |      5,500       26.93       93.66
   University |      1,296        6.34      100.00
--------------+-----------------------------------
        Total |     20,426      100.00
r; t=0.00 15:14:22

. 
. * Employment status from Q93A
. recode Q93A ///
>     (0 = 0) /// No (not looking)
>     (1 = 1) /// No (looking)
>     (2 = 2) /// Yes, part time
>     (3 = 3) /// Yes, full time
>     (8 = .) ///
>     (9 = .) ///
>     (9994 = .), gen(recoded_employment)
(26 differences between Q93A and recoded_employment)
r; t=0.01 15:14:22

. 
. label define employment_status_lbl ///
>     0 "No (not looking)" ///
>     1 "No (looking)" ///
>     2 "Yes, part time" ///
>     3 "Yes, full time"
r; t=0.00 15:14:22

. 
. label values recoded_employment employment_status_lbl
r; t=0.00 15:14:22

. label var recoded_employment "Re-coded Employment Status"
r; t=0.00 15:14:22

. 
. * Broader employment groups
. recode recoded_employment (0 1 = 1) (2 = 2) (3 = 3), gen(emp_group)
(7,739 differences between recoded_employment and emp_group)
r; t=0.00 15:14:22

. label define emp_group_lbl ///
>     1 "Not employed" ///
>     2 "Part-time" ///
>     3 "Full-time"
r; t=0.00 15:14:22

. label values emp_group emp_group_lbl
r; t=0.00 15:14:22

. label var emp_group "Employment status"
r; t=0.00 15:14:22

. tab emp_group

  Employment |
      status |      Freq.     Percent        Cum.
-------------+-----------------------------------
Not employed |     13,739       67.23       67.23
   Part-time |      2,146       10.50       77.73
   Full-time |      4,552       22.27      100.00
-------------+-----------------------------------
       Total |     20,437      100.00
r; t=0.00 15:14:22

. 
. * Safety walking in neighbourhood – Q7A
. recode Q7A ///
>     (0 = 0) ///
>     (1 = 1) ///
>     (2 = 2) ///
>     (3 = 3) ///
>     (4 = 4) ///
>     (8 = .) ///
>     (9 = .), gen(recoded_Q7A)
(20 differences between Q7A and recoded_Q7A)
r; t=0.01 15:14:22

. 
. label define unsafe_walk_lbl ///
>     0 "Never" ///
>     1 "Just once or twice" ///
>     2 "Several times" ///
>     3 "Many times" ///
>     4 "Always"
r; t=0.00 15:14:22

. label values recoded_Q7A unsafe_walk_lbl
r; t=0.00 15:14:22

. label var recoded_Q7A "Feeling unsafe walking in neighbourhood"
r; t=0.00 15:14:22

. 
. recode recoded_Q7A (0 1 = 1) (2 = 2) (3 4 = 3), gen(safety_group)
(11,165 differences between recoded_Q7A and safety_group)
r; t=0.01 15:14:22

. label define safety_group_lbl ///
>     1 "Never or rarely" ///
>     2 "Occasionally" ///
>     3 "Frequently"
r; t=0.00 15:14:22

. label values safety_group safety_group_lbl
r; t=0.00 15:14:22

. label var safety_group "Safety Status"
r; t=0.00 15:14:22

. gen safety = safety_group
(20 missing values generated)
r; t=0.00 15:14:22

. 
. * Fear of crime at home – Q7B
. recode Q7B ///
>     (0 = 0) ///
>     (1 = 1) ///
>     (2 = 2) ///
>     (3 = 3) ///
>     (4 = 4) ///
>     (8 = .) ///
>     (9 = .), gen(recoded_Q7B)
(16 differences between Q7B and recoded_Q7B)
r; t=0.01 15:14:22

. 
. label define fear_crime_home_lbl ///
>     0 "Never" ///
>     1 "Just once or twice" ///
>     2 "Several times" ///
>     3 "Many times" ///
>     4 "Always"
r; t=0.00 15:14:22

. label values recoded_Q7B fear_crime_home_lbl
r; t=0.00 15:14:22

. label var recoded_Q7B "Fearing crime at home (original categories)"
r; t=0.00 15:14:22

. 
. recode recoded_Q7B (0 1 = 1) (2 = 2) (3 4 = 3), gen(fearing_crime)
(12,672 differences between recoded_Q7B and fearing_crime)
r; t=0.01 15:14:22

. label define fearing_crime_lbl ///
>     1 "Never or rarely" ///
>     2 "Occasionally" ///
>     3 "Frequently"
r; t=0.00 15:14:22

. label values fearing_crime fearing_crime_lbl
r; t=0.00 15:14:22

. label var fearing_crime "Fearing Crime at Home"
r; t=0.00 15:14:22

. tab fearing_crime

  Fearing Crime |
        at Home |      Freq.     Percent        Cum.
----------------+-----------------------------------
Never or rarely |     14,188       69.39       69.39
   Occasionally |      2,945       14.40       83.79
     Frequently |      3,314       16.21      100.00
----------------+-----------------------------------
          Total |     20,447      100.00
r; t=0.00 15:14:22

. 
. * Discussing politics – Q8
. recode Q8 ///
>     (0 = 0) ///
>     (1 = 1) ///
>     (2 = 2) ///
>     (8 = .) ///
>     (9 = .), gen(recoded_Q8)
(60 differences between Q8 and recoded_Q8)
r; t=0.01 15:14:22

. 
. label define politics_lbl ///
>     0 "Never" ///
>     1 "Occasionally" ///
>     2 "Frequently"
r; t=0.00 15:14:22

. label values recoded_Q8 politics_lbl
r; t=0.00 15:14:22

. label var recoded_Q8 "Frequency of discussing politics (original)"
r; t=0.00 15:14:22

. 
. recode recoded_Q8 (0 = 0) (1 = 1) (2 = 2), gen(discuss_politics)
(0 differences between recoded_Q8 and discuss_politics)
r; t=0.00 15:14:22

. label define discuss_politics_lbl ///
>     0 "Never discuss politics" ///
>     1 "Occasionally discuss politics" ///
>     2 "Frequently discuss politics"
r; t=0.00 15:14:22

. label values discuss_politics discuss_politics_lbl
r; t=0.00 15:14:22

. label var discuss_politics "Frequency of discussing politics (grouped)"
r; t=0.00 15:14:22

. 
. * EA-level infrastructure (EA_FAC_C, EA_SEC_B, EA_SVC_B)
. replace EA_FAC_C = . if EA_FAC_C == 9
(0 real changes made)
r; t=0.00 15:14:22

. replace EA_SEC_B = . if EA_SEC_B == 9
(0 real changes made)
r; t=0.00 15:14:22

. replace EA_SVC_B = . if EA_SVC_B == 9
(0 real changes made)
r; t=0.00 15:14:22

. 
. gen police_station = (EA_FAC_C == 1)
r; t=0.00 15:14:22

. gen soldiers_army  = (EA_SEC_B == 1)
r; t=0.00 15:14:22

. gen piped_water    = (EA_SVC_B == 1)
r; t=0.00 15:14:22

. 
. label var police_station "Police station in town/village"
r; t=0.00 15:14:22

. label var soldiers_army  "Soldiers/army in town/village"
r; t=0.00 15:14:22

. label var piped_water    "Piped water system in town/village"
r; t=0.00 15:14:22

. 
. ***************************************************************
. * 1.3 OUTCOMES – DEMOCRACY, AUTHORITARIAN ALTERNATIVES, ETC.
. ***************************************************************
. 
. * Support for democracy – Q23
. recode Q23 ///
>     (1 = 1) ///
>     (2 = 2) ///
>     (3 = 3) ///
>     (8 = .) ///
>     (9 = .), gen(recoded_Q23)
(354 differences between Q23 and recoded_Q23)
r; t=0.01 15:14:22

. 
. label define democracy_support_lbl ///
>     1 "It doesn't matter what kind of government" ///
>     2 "Non-democratic government can be preferable" ///
>     3 "Democracy is preferable"
r; t=0.00 15:14:22

. label values recoded_Q23 democracy_support_lbl
r; t=0.00 15:14:22

. label var recoded_Q23 "Support for democracy (original)"
r; t=0.00 15:14:22

. 
. recode recoded_Q23 (1 2 = 1) (3 = 2), gen(support_democracy_group)
(16,841 differences between recoded_Q23 and support_democracy_group)
r; t=0.01 15:14:22

. label define support_democracy_group_lbl ///
>     1 "Against democracy or indifferent" ///
>     2 "Support democracy"
r; t=0.00 15:14:22

. label values support_democracy_group support_democracy_group_lbl
r; t=0.00 15:14:22

. label var support_democracy_group "Support for democracy (grouped)"
r; t=0.00 15:14:22

. 
. * Extent of democracy – Q30
. recode Q30 ///
>     (1 = 1) ///
>     (2 = 2) ///
>     (3 = 3) ///
>     (4 = 4) ///
>     (8 = .) ///
>     (9 = .) ///
>     (98 = .), gen(recoded_Q30)
(606 differences between Q30 and recoded_Q30)
r; t=0.01 15:14:22

. 
. label define democracy_extent_lbl ///
>     1 "Not a democracy" ///
>     2 "A democracy with major problems" ///
>     3 "A democracy with minor problems" ///
>     4 "A full democracy"
r; t=0.00 15:14:22

. label values recoded_Q30 democracy_extent_lbl
r; t=0.00 15:14:22

. label var recoded_Q30 "Extent of democracy (original)"
r; t=0.00 15:14:22

. 
. recode recoded_Q30 (1 = 1) (2 3 = 2) (4 = 3), gen(democracy_group)
(9,539 differences between recoded_Q30 and democracy_group)
r; t=0.00 15:14:22

. label define democracy_group_lbl ///
>     1 "Not a democracy" ///
>     2 "Democracy with problems" ///
>     3 "Full democracy"
r; t=0.00 15:14:22

. label values democracy_group democracy_group_lbl
r; t=0.00 15:14:22

. label var democracy_group "Extent of democracy (grouped)"
r; t=0.00 15:14:22

. 
. 
. * Authoritarian alternatives – Q22A/B/C
. recode Q22B ///
>     (1 = 1) ///
>     (2 = 2) ///
>     (3 = 3) ///
>     (4 = 4) ///
>     (5 = 5) ///
>     (8 = .) ///
>     (9 = .), gen(recoded_Q22B)
(330 differences between Q22B and recoded_Q22B)
r; t=0.01 15:14:22

. 
. label define military_rule_rejection_lbl ///
>     1 "Strongly disapprove" ///
>     2 "Disapprove" ///
>     3 "Neither approve nor disapprove" ///
>     4 "Approve" ///
>     5 "Strongly approve"
r; t=0.00 15:14:22

. label values recoded_Q22B military_rule_rejection_lbl
r; t=0.00 15:14:22

. label var recoded_Q22B "Rejection of military rule (original)"
r; t=0.00 15:14:22

. 
. recode recoded_Q22B (1 2 = 3) (3 = 2) (4 5 = 1), gen(rejection_military_rule)
(20,133 differences between recoded_Q22B and rejection_military_rule)
r; t=0.00 15:14:22

. label define rejection_military_rule_lbl ///
>     1 "Support military rule" ///
>     2 "Neutral" ///
>     3 "Reject military rule"
r; t=0.00 15:14:22

. label values rejection_military_rule rejection_military_rule_lbl
r; t=0.00 15:14:22

. label var rejection_military_rule "Rejection of military rule (grouped)"
r; t=0.00 15:14:22

. 
. recode Q22A ///
>     (1 = 1) ///
>     (2 = 2) ///
>     (3 = 3) ///
>     (4 = 4) ///
>     (5 = 5) ///
>     (8 = .) ///
>     (9 = .), gen(recoded_Q22A)
(261 differences between Q22A and recoded_Q22A)
r; t=0.01 15:14:22

. 
. label define one_party_rule_rejection_lbl ///
>     1 "Strongly disapprove" ///
>     2 "Disapprove" ///
>     3 "Neither approve nor disapprove" ///
>     4 "Approve" ///
>     5 "Strongly approve"
r; t=0.00 15:14:22

. label values recoded_Q22A one_party_rule_rejection_lbl
r; t=0.00 15:14:22

. label var recoded_Q22A "Rejection of one-party rule (original)"
r; t=0.00 15:14:22

. 
. recode recoded_Q22A (1 2 = 3) (3 = 2) (4 5 = 1), gen(rejection_one_party_rule)
(20,202 differences between recoded_Q22A and rejection_one_party_rule)
r; t=0.01 15:14:22

. label define rejection_one_party_rule_lbl ///
>     1 "Support one-party rule" ///
>     2 "Neutral" ///
>     3 "Reject one-party rule"
r; t=0.00 15:14:22

. label values rejection_one_party_rule rejection_one_party_rule_lbl
r; t=0.00 15:14:22

. label var rejection_one_party_rule "Rejection of one-party rule (grouped)"
r; t=0.00 15:14:22

. 
. recode Q22C ///
>     (1 = 1) ///
>     (2 = 2) ///
>     (3 = 3) ///
>     (4 = 4) ///
>     (5 = 5) ///
>     (8 = .) ///
>     (9 = .), gen(recoded_Q22C)
(336 differences between Q22C and recoded_Q22C)
r; t=0.01 15:14:22

. 
. label define one_man_rule_rejection_lbl ///
>     1 "Strongly disapprove" ///
>     2 "Disapprove" ///
>     3 "Neither approve nor disapprove" ///
>     4 "Approve" ///
>     5 "Strongly approve"
r; t=0.00 15:14:22

. label values recoded_Q22C one_man_rule_rejection_lbl
r; t=0.00 15:14:22

. label var recoded_Q22C "Rejection of one-man rule (original)"
r; t=0.00 15:14:22

. 
. recode recoded_Q22C (1 2 = 3) (3 = 2) (4 5 = 1), gen(rejection_one_man_rule)
(20,127 differences between recoded_Q22C and rejection_one_man_rule)
r; t=0.01 15:14:22

. label define rejection_one_man_rule_lbl ///
>     1 "Support one-man rule" ///
>     2 "Neutral" ///
>     3 "Reject one-man rule"
r; t=0.00 15:14:22

. label values rejection_one_man_rule rejection_one_man_rule_lbl
r; t=0.00 15:14:22

. label var rejection_one_man_rule "Rejection of one-man rule (grouped)"
r; t=0.00 15:14:22

. 
. * Voting – Q13
. recode Q13 ///
>     (0 = 0) ///
>     (1 = .) ///
>     (2 = .) ///
>     (3 = 1) ///
>     (-1 = .) ///
>     (8 = .) ///
>     (9 = .), gen(recoded_Q13)
(15,372 differences between Q13 and recoded_Q13)
r; t=0.01 15:14:22

. 
. label define voting_lbl 0 "Did not vote" 1 "Voted"
r; t=0.00 15:14:22

. label values recoded_Q13 voting_lbl
r; t=0.00 15:14:22

. label var recoded_Q13 "Voting in last national election"
r; t=0.00 15:14:22

. 
. recode recoded_Q13 (0 = 0) (1 = 1), gen(voted)
(0 differences between recoded_Q13 and voted)
r; t=0.00 15:14:22

. label values voted voting_lbl
r; t=0.00 15:14:22

. label var voted "Voting status: voted (1) vs not (0)"
r; t=0.00 15:14:22

. 
. 
. * Composite: rejection of authoritarian alternatives
. egen auth_support = rowmean(rejection_military_rule rejection_one_party_rule rejection_one_man_rule)
(101 missing values generated)
r; t=0.01 15:14:22

. label var auth_support "Rejection of authoritarian alternatives"
r; t=0.00 15:14:22

. 
. * Convenience copies for democracy outcomes
. gen demo_support       = support_democracy_group
(354 missing values generated)
r; t=0.00 15:14:22

. gen demo_rated         = democracy_group
(606 missing values generated)
r; t=0.00 15:14:22

. 
. ***************************************************************
. * 1.4 IDs AND STRINGS FOR MATCHING (R9)
. ***************************************************************
. 
. * Unique respondent ID
. gen id1 = _n
r; t=0.00 15:14:22

. * Locality and country for matching
. replace locality1 = trim(lower(locality1))
(0 real changes made)
r; t=0.00 15:14:22

. decode COUNTRY, gen(country1)
r; t=0.00 15:14:22

. replace country1 = trim(lower(country1))
(20,463 real changes made)
r; t=0.00 15:14:22

. 
. * Combined locality + country
. gen locality_country1 = locality1 + " " + country1
r; t=0.00 15:14:22

. 
. save "${data_new}/R9_c.dta", replace
(file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated data/R9_c.dta
    not found)
file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated data/R9_c.dta
    saved
r; t=0.07 15:14:22

. 
. ***************************************************************
. * 2. ACLED – DATES, TIME_EXPOSED, LOCALITY STRINGS
. ***************************************************************
. 
. use "${data}/Original_data_acled.dta", clear
r; t=3.22 15:14:26

. 
. * Event date as numeric
. gen eventdate = date(event_date, "YMD")
r; t=0.00 15:14:26

. format eventdate %td
r; t=0.00 15:14:26

. label var eventdate "Event date (numeric Stata date)"
r; t=0.00 15:14:26

. 
. * Time since first event within country
. * (assuming 'country' is string)
. egen min_eventdate = min(eventdate), by(country)
r; t=0.00 15:14:26

. gen time_exposed = eventdate - min_eventdate + 1 if !missing(eventdate)
r; t=0.00 15:14:26

. label var time_exposed "Day of violence timeline within country (1 = first event)"
r; t=0.00 15:14:26

. 
. * IDs and cleaned locality/country
. gen id2 = _n
r; t=0.00 15:14:26

. gen country2 = trim(lower(country))
r; t=0.00 15:14:26

. 
. * Combined locality + country
. gen locality_country2 = locality2 + " " + country2
r; t=0.00 15:14:26

. save "${data_new}/acled_c.dta", replace
(file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated
    data/acled_c.dta not found)
file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated
    data/acled_c.dta saved
r; t=0.10 15:14:26

. 
. ***************************************************************
. * 3. FUZZY MATCHING – matchit ON locality+country
. ***************************************************************
. 
. *--------------------------------------------------------------
. * 1. Get UNIQUE locality_country in R9
. *--------------------------------------------------------------
. use "${data_new}/R9_c.dta", clear
r; t=0.00 15:14:26

. 
. * Keep only the string we match on
. keep locality_country1
r; t=0.00 15:14:26

. 
. * One row per locality_country1
. duplicates drop locality_country1, force

Duplicates in terms of locality_country1

(20,265 observations deleted)
r; t=0.01 15:14:26

. 
. * ID required by matchit
. gen locid1 = _n
r; t=0.00 15:14:26

. 
. save "${data_new}/R9_loc_unique.dta", replace
(file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated
    data/R9_loc_unique.dta not found)
file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated
    data/R9_loc_unique.dta saved
r; t=0.00 15:14:26

. 
. 
. *--------------------------------------------------------------
. * 2. Get UNIQUE locality_country in ACLED
. *--------------------------------------------------------------
. use "${data_new}/acled_c.dta", clear
r; t=0.01 15:14:26

. 
. * Keep the string + event id
. keep id2 locality_country2
r; t=0.00 15:14:26

. 
. 
. * ID required by matchit (for the using side)
. gen locid2 = _n
r; t=0.00 15:14:26

. 
. save "${data_new}/acled_loc_unique.dta", replace
(file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated
    data/acled_loc_unique.dta not found)
file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated
    data/acled_loc_unique.dta saved
r; t=0.00 15:14:26

. 
. 
. *--------------------------------------------------------------
. * 3. Fuzzy match on unique localities (MUCH smaller)
. *--------------------------------------------------------------
. capture which matchit
r; t=0.01 15:14:26

. if _rc ssc install matchit
r; t=0.00 15:14:26

. 
. use "${data_new}/R9_loc_unique.dta", clear
r; t=0.00 15:14:26

. 
. matchit locid1 locality_country1 using "${data_new}/acled_loc_unique.dta", ///
>     idu(locid2) txtu(locality_country2) threshold(0.90)
Matching current dataset with /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Co
> nflict project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated data/acled
> _loc_unique.dta
Similarity function: bigram
Loading USING file: /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict pro
> ject/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated data/acled_loc_uniqu
> e.dta
Indexing USING file.
0%
20%
40%
60%
80%
Done!
Computing results
        Percent completed ...   (search space saved by index so far)
        20%               ...   (26%)
        40%               ...   (33%)
        60%               ...   (30%)
        80%               ...   (29%)
        Done!
Total search space saved by index: 28%
r; t=40.30 15:15:06

. 
. save "${data_new}/loc_match.dta", replace
(file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated
    data/loc_match.dta not found)
file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated
    data/loc_match.dta saved
r; t=0.40 15:15:07

. 
. 
. *--------------------------------------------------------------
. * 4. Bring id2 back to locality level, keep BEST match per locality
. *--------------------------------------------------------------
. use "${data_new}/loc_match.dta", clear
r; t=0.01 15:15:07

. 
. * Attach id2 from the ACLED locality file
. merge m:1 locid2 using "${data_new}/acled_loc_unique.dta", keep(match) nogen
(variable locid2 was int, now float to accommodate using data's values)

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                            20,463  
    -----------------------------------------
r; t=2.15 15:15:09

. 
. * If matchit returns multiple candidate matches per locid1,
. * keep the one with the highest similarity score
. sort locid1 similscore
r; t=0.00 15:15:09

. by locid1: keep if _n == _N   // last = highest similscore
(20,265 observations deleted)
r; t=0.00 15:15:09

. 
. * Keep only what we need to merge back to individuals
. keep locality_country1 id2 similscore
r; t=0.00 15:15:09

. 
. save "${data_new}/loc_to_id2.dta", replace
(file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated
    data/loc_to_id2.dta not found)
file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated
    data/loc_to_id2.dta saved
r; t=0.00 15:15:09

. 
. 
. *--------------------------------------------------------------
. * 5. Merge event ID back to full R9 data
. *--------------------------------------------------------------
. use "${data_new}/R9_c.dta", clear
r; t=2.99 15:15:12

. 
. * One id2 per locality assigned to ALL respondents in that locality
. merge m:1 locality_country1 using "${data_new}/loc_to_id2.dta", ///
>     keep(master match) nogen

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                            20,463  
    -----------------------------------------
r; t=0.04 15:15:12

. 
. * Now each respondent has an ACLED event ID (id2)
. save "${data_new}/R9_with_id2.dta", replace
(file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated
    data/R9_with_id2.dta not found)
file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated
    data/R9_with_id2.dta saved
r; t=0.01 15:15:12

. 
. 
. ***************************************************************
. * 6. FINAL MERGE: R9 + ACLED EVENTS
. ***************************************************************
. 
. * Start from respondent data with matched id2
. use "${data_new}/R9_with_id2.dta", clear
r; t=0.00 15:15:12

. 
. * Merge ACLED information by id2
. merge m:1 id2 using "${data_new}/acled_c.dta", keep(match) nogen

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                            20,463  
    -----------------------------------------
r; t=2.92 15:15:15

. 
. * Restrict to Afrobarometer fieldwork window
. keep if inrange(eventdate, field_start, field_end)
(0 observations deleted)
r; t=0.00 15:15:15

. 
. 
. * Time difference between interview and matched event (days)
. gen tdiff = intervdate - eventdate if !missing(intervdate) & !missing(eventdate)
r; t=0.00 15:15:15

. label var tdiff "Days between interview and matched event"
r; t=0.00 15:15:15

. summ tdiff

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
       tdiff |     20,463    99.43635    227.6836       -479        538
r; t=0.00 15:15:15

. 
. * Post-event indicator (example)
. gen time_zero = (tdiff > 0) if !missing(tdiff)
r; t=0.00 15:15:15

. label var time_zero "Interview after matched event (1 = yes)"
r; t=0.00 15:15:15

. 
. * Survey year (for FE) – create only if missing
. capture confirm variable surveyyear
r; t=0.00 15:15:15

. if _rc {
.     gen surveyyear = year(DATEINTR)
r; t=0.00 15:15:15
.     label var surveyyear "Survey year (from DATEINTR)"
r; t=0.00 15:15:15
. }
r; t=0.00 15:15:15

. 
. * 'year' variable for country-year merges – create only if missing
. capture confirm variable year
r; t=0.00 15:15:15

. if _rc {
.     capture confirm variable surveyyear
r; t=0.00 15:15:15
.     if !_rc {
.         gen year = surveyyear
r; t=0.00 15:15:15
.     }
r; t=0.00 15:15:15
.     else {
.         gen year = year(DATEINTR)
r; t=0.00 15:15:15
.     }
r; t=0.00 15:15:15
. }
r; t=0.00 15:15:15

. 
. * Numeric country ID (if not already there)
. capture confirm variable cntrynum
r; t=0.00 15:15:15

. if _rc {
.     encode country, gen(cntrynum)
r; t=0.00 15:15:15
. }
r; t=0.00 15:15:15

. 
. save "${data_new}/final_d.dta", replace
(file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated
    data/final_d.dta not found)
file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated
    data/final_d.dta saved
r; t=0.20 15:15:15

. 
. 
. ***************************************************************
. * 5. MACRO-LEVEL MERGES (V-DEM + HDI)
. ***************************************************************
. 
. *--------------------------------------------------------------
. * 5.1 Build libhdi.dta from vdem + macro
. *--------------------------------------------------------------
. 
. use "${data}/vdem.dta", clear
r; t=0.97 15:15:16

. merge m:1 cntrynum using "${data}/macro.dta"
(label cntrynum already defined)

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                                93  (_merge==3)
    -----------------------------------------
r; t=0.62 15:15:17

. keep if _merge == 3
(0 observations deleted)
r; t=0.00 15:15:17

. drop _merge
r; t=0.00 15:15:17

. 
. rename HumanDevelopmentIndexHDI hdi
r; t=0.10 15:15:17

. label var hdi "Human Development Index"
r; t=0.00 15:15:17

. save "${data_new}/libhdi.dta", replace
(file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated
    data/libhdi.dta not found)
file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/output/Generated
    data/libhdi.dta saved
r; t=0.00 15:15:17

. 
. 
. *--------------------------------------------------------------
. * 5.2 Merge macro data (HDI + V-Dem) into micro data
. *--------------------------------------------------------------
. use "${data_new}/final_d.dta", clear
r; t=0.01 15:15:17

. 
. * Drop any existing merge flag, regardless of origin
. capture drop _merge
r; t=0.00 15:15:17

. 
. * Merge with unique macro file
. merge m:1 cntrynum year using "${data_new}/libhdi.dta", gen(merge_hdi)
(label cntrynum already defined)

    Result                      Number of obs
    -----------------------------------------
    Not matched                            43
        from master                         0  (merge_hdi==1)
        from using                         43  (merge_hdi==2)

    Matched                            20,463  (merge_hdi==3)
    -----------------------------------------
r; t=0.37 15:15:17

. 
. * Keep only matched country-years (optional but recommended)
. keep if merge_hdi == 3
(43 observations deleted)
r; t=0.00 15:15:17

. drop merge_hdi
r; t=0.00 15:15:17

. 
. save "${data}/R9_final.dta", replace
file /Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict
    project/Conflict-Nigeria/Observationaldata/R9-Acled/JCR replication/Original data/R9_final.dta
    saved
r; t=0.35 15:15:17

. ta cntrynum

     country |      Freq.     Percent        Cum.
-------------+-----------------------------------
      Angola |        280        1.37        1.37
       Benin |        792        3.87        5.24
Burkina Faso |        672        3.28        8.52
    Cameroon |        624        3.05       11.57
    Eswatini |      1,200        5.86       17.44
    Ethiopia |      1,232        6.02       23.46
       Gabon |        120        0.59       24.04
      Gambia |        144        0.70       24.75
       Ghana |      1,577        7.71       32.45
      Guinea |        192        0.94       33.39
       Kenya |      1,264        6.18       39.57
     Lesotho |         56        0.27       39.84
     Liberia |        328        1.60       41.45
  Madagascar |        680        3.32       44.77
      Malawi |        528        2.58       47.35
        Mali |      1,200        5.86       53.21
  Mauritania |         64        0.31       53.53
     Morocco |        952        4.65       58.18
  Mozambique |        712        3.48       61.66
     Namibia |         48        0.23       61.89
       Niger |      1,128        5.51       67.40
     Nigeria |      1,488        7.27       74.68
     Senegal |        544        2.66       77.33
Sierra Leone |        480        2.35       79.68
South Africa |      1,166        5.70       85.38
       Sudan |         80        0.39       85.77
    Tanzania |        792        3.87       89.64
        Togo |        640        3.13       92.77
      Uganda |        104        0.51       93.28
      Zambia |        472        2.31       95.58
    Zimbabwe |        904        4.42      100.00
-------------+-----------------------------------
       Total |     20,463      100.00
r; t=0.00 15:15:17

. ***************************************************************
. * END OF DO-FILE
. ***************************************************************
. 
end of do-file

r; t=57.94 15:15:17
. do "/Users/souleymane.yameogo/Library/CloudStorage/Dropbox/WP3_OnlineCivics/Conflict project/Conflict-
> Nigeria/Observationaldata/R9-Acled/JCR replication/02_analysis.do"

. ***************************************************************
. * Afrobarometer R9 x ACLED – Cleaned, Replicable Pipeline
. * (copy–paste into a .do file)
. ***************************************************************
. //--------------------------------------------------------------
. // 02_analysis.do — Replication cleaning script
. // Project: "The Impact of Terrorism on Democratic Support in Africa"
. //--------------------------------------------------------------
. version 18.0
r; t=0.02 15:16:56

. clear all
r; t=0.16 15:16:57

. set more off
r; t=0.00 15:16:57

. set rmsg on
r; t=0.00 15:16:57

. cap set scheme plotplain
r; t=0.00 15:16:57

. 
. * --------------------------------------------------------------
. * Project root (robust to where the do-file is run from)
. * --------------------------------------------------------------
. local thisdo = c(filename)
r; t=0.00 15:16:57

. 
. * Fallback if c(filename) is empty (rare)
. if "`thisdo'" == "" {
.     global root "`c(pwd)'"
r; t=0.00 15:16:57
. }
r; t=0.00 15:16:57

. else {
.     * Directory containing this do-file
.     local dodir : dirname "`thisdo'"
r; t=0.00 15:16:57
.     * Project root is parent of /dofile
.     local root  : dirname "`dodir'"
r; t=0.00 15:16:57
.     global root "`root'"
r; t=0.00 15:16:57
. }
r; t=0.00 15:16:57

. 
. * If someone runs from inside /dofile (extra safety)
. if substr("${root}", -6, 6) == "dofile" {
.     global root = substr("${root}", 1, length("${root}")-6)
r; t=0.00 15:16:57
. }
r; t=0.00 15:16:57

. 
. *--------------------------------------------------------------
. * 0. PATHS (relative; no machine-specific paths)
. *--------------------------------------------------------------
. 
. global data   "${root}/Original data"
r; t=0.00 15:16:57

. global do     "${root}/dofile"
r; t=0.00 15:16:57

. global out    "${root}/output"
r; t=0.00 15:16:57

. global table  "${out}/tables"
r; t=0.00 15:16:57

. global graph  "${out}/graphs"
r; t=0.00 15:16:57

. global data_new  "${out}/Generated data"
r; t=0.00 15:16:57

. 
. cap mkdir "${out}"
r; t=0.00 15:16:57

. cap mkdir "${table}"
r; t=0.00 15:16:57

. cap mkdir "${graph}"
r; t=0.00 15:16:57

. cap mkdir "${data_new}"
r; t=0.00 15:16:57

. 
. cap log close _all
